import { NFBaseService, PageDataType } from '@/services/NFBaseService'
import { makeAutoObservable } from 'mobx'

class NFBaseModel<V, QD, UD> {
  public service: NFBaseService<V, QD, UD>
  public list: V[] = []
  public page: PageDataType<V> = { current: 0, data: [], pages: 0, total: 0 }

  constructor(service: NFBaseService<V, QD, UD>) {
    makeAutoObservable(this, {}, { autoBind: true })
    this.service = service
  }

  public setList = (data: V[]) => {
    this.list = data
  }
  public flushList = async (params: QD) => {
    let res = await this.service.list(params)
    this.setList(res)
  }

  public setPage = (data: PageDataType<V>) => {
    this.page = data
  }
  public flushPage = async (params: QD) => {
    let res = await this.service.page(params)
    this.setPage(res)
  }
}

export default NFBaseModel
